package threadDemo12;

public class Food extends Thread{
    @Override
    public void run() {
        while (true){
            synchronized (Desk.lock){
                //先判断桌子上是否有面条
                if (Desk.foodFlag==0){
                    try {
                        //如果没有就等待
                        Desk.lock.wait();//让当前线程跟锁进行绑定
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }else {
                    //把吃的总数减一
                    Desk.count--;
                    //如果有就开吃
                    System.out.println("还能吃"+Desk.count+"碗");
                    //吃完唤醒厨师继续做
                    Desk.lock.notifyAll();
                    //修改桌子的状态
                    Desk.foodFlag=0;
                }
            }
        }
    }
}
